<link href="<?php echo URL::base() ?>media/vendor/css/ui-lightness/jquery-ui-1.10.4.custom.css" rel="stylesheet">
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-1.10.2.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/jquery-ui-1.10.4.custom.js"></script>
<!--
<script src="<?php echo URL::base() ?>media/vendor/js/jquery.ui.datepicker-zh-TW.js"></script>
-->
<script src="<?php echo URL::base() ?>media/laydate/laydate.js"></script>

<div class="container-fluid">
<form class="form-horizontal" action="<?php echo url::base(TRUE) ?>quality/selectunquality" name="form1"
      onsubmit="return checkForm();" method="get">
    <div class="control-group">
        <label class="control-label">是否库内:</label>
        <div class="controls">
            <select name="no_purchaseorder_id">
                <option value="0" <?php if ($getback['no_purchaseorder_id'] == 0) {
                    echo "selected = 'selected'";
                } ?>>请选择
                </option>
                <option value="20" <?php if ($getback['no_purchaseorder_id'] == 20) {
                    echo "selected = 'selected'";
                } ?>>非库内
                </option>
                <option value="10" <?php if ($getback['no_purchaseorder_id'] == 10) {
                    echo "selected = 'selected'";
                } ?>>库内
                </option>
            </select>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">质检时间从:</label>
        <div class="controls">
        <input  class="input-medium datepicker" type="text"
               value="<?php if (isset($getback['date_from'])) {
                   echo $getback['date_from'];
               } ?>" name='date_from' id="date_from"/>
        到 <input  class="input-medium datepicker" type="text"
                 value="<?php if (isset($getback['date_to'])) {
                     echo $getback['date_to'];
                 } ?>" name='date_to' id="date_to"/>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">VMI预约单号:</label>
        <div class="controls">
            <input  type="text"   name="purchaseid" value="<?php if (isset($getback['purchaseid'])) {
                                                  echo $getback['purchaseid'];
                                              } ?>"/>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">供应商:</label>
        <div class="controls">
        <input  type="hidden" name="supplierid" value="<?php
            echo $getback['supplierid']; ?>"/>
        <input id="search1"  type="text" name="suppliername" value="<?php if (isset($getback['suppliername'])) {
            echo $getback['suppliername'];
        } ?>"/>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">SKU:</label>
        <div class="controls">
        <input   type="text" name="sku"
                                             value="<?php if (isset($getback['sku'])) {
                                                 echo $getback['sku'];
                                             } ?>"/>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">计划员:</label>
        <div class="controls">
        <input  type="text" name="purid"
                                             value="<?php if (isset($getback['purname'])) {
                                                 echo $getback['purname'];
                                             } ?>"/>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">状态:</label>
        <div class="controls">
        <select name="status" >
            <option value="">选择处理状态</option>
            <?php foreach ($status as $key => $value) { ?>
                <option value="<?php echo $value['number']; ?>"
                    <?php if (isset($getback['status']) and ($getback['status'] == $value['number'])) {
                        echo "selected='selected'";
                    } ?> ><?php echo $value['value']; ?></option>
            <?php } ?>
        </select>
        </div>
    </div>
    <div class="control-group">
        <div class="controls">
        <input class="btn btn-info" type="submit" name="sub" value="查询"/>
        <input class="btn btn-default" type="button" name="downbtn" id="downbtn"
               value="下载"/>
        </div>
    </div>
</form>
</div>
<div id="pageContent2">
    <div id="content"><?php if (!empty($result)) { ?>
            <table style="table-layout:fixed;" class="table table1 table-hover table-condensed">
                <thead>
                <tr>
                    <th width="90">不良品单号</th>
                    <th width="100">VMI预约单号</th>
                    <th>质检单号</th>
                    <th>SKU</th>
                    <th>中文名称</th>
                    <th>供应商</th>
                    <th width="80">不合格量</th>
                    <th>质检时间</th>
                    <th width="80">计划员</th>
                    <th>质检不合格原因</th>
                    <th width="80">质检员</th>
                    <th width="80">状态</th>
                    <th width="60">操作</th>
                </tr>
                </thead>
                <tbody>
                <?php foreach ($result as $key => $value) { ?>
                    <tr>
                        <td>
                            <?php echo $value['id']; ?>
                        </td>
                        <td>
                            <?php echo $value['purchaseorder_id']; ?>
                        </td>
                        <td><?php echo $value['check_detail_id']; ?></td>
                        <td>
                            <?php echo $value['sku']; ?>
                        </td>
                        <td>
                            <?php echo $value['sku_name']; ?>
                        </td>
                        <td><?php echo $value['supplier']; ?></td>
                        <td><?php echo $value['quantity']; ?></td>
                        <td>
                            <?php echo $value['check_time']; ?>
                        </td>
                        <td>
                            <?php echo $value['purchase_man']; ?>
                        </td>
                        <td class="enleter">
                            <?php echo $value['quality_remark']; ?>
                        </td>
                        <td>
                            <?php echo $quality_men[$value['quality_man']]; ?>
                        </td>
                        <td>
                            <?php echo $value['status']; ?>
                        </td>
                        <td style="text-align:center;">
                            <input class="btn btn-info btn-small" type='button'
                                   onclick="return print(<?php echo $value['id']; ?>,<?php echo $value['statusid']; ?>,<?php echo $value['purchaseorder_id']; ?>);"
                                   id="but" value='修改'/>
                        </td>

                    </tr>

                <?php } ?>


                </tbody>

            </table>
        <?php } ?>
    </div>
</div>

<?php if (isset($page_links)) {
    echo $page_links;
} ?>

<script type="text/javascript">
    $(document).ready(function () {
        laydate.render({
            elem: '#date_from'
        });
        laydate.render({
            elem: '#date_to'
        });
        $("#search1").autocomplete({
            source: '<?php echo URL::base() ?>purchase/get_supplier',
            select: function (event, ui) {
                $("#search1").val(ui.item.name);
               $("input[name=supplierid]").val(ui.item.id);
                return false;
            }
        });

        $("#downbtn").click(function () {
            var no_purchaseorder_id = $.trim($("select[name=no_purchaseorder_id]").val());
            var sku = $.trim($("input[name=sku]").val());
            var date_from = $.trim($("input[name=date_from]").val());
            var date_to = $.trim($("input[name=date_to]").val());
            var purchaseid = $.trim($("input[name=purchaseid]").val());
            var supplierid = $.trim($("input[name=supplierid]").val());
            var purid = $.trim($("input[name=purid]").val());
            var status = $("select[name='status']").val();
            var uri = 'sku=' + sku + '&date_from=' + date_from + '&date_to=' + date_to + '&purchaseid=' + purchaseid + '&supplierid=' + supplierid + '&purid=' + purid + '&status=' + status + '&no_purchaseorder_id=' + no_purchaseorder_id;
            window.location.href = "<?php echo URL::base()?>quality/download?" + uri;
        });
    });
</script>
<script type="text/javascript">

    function checkForm() {

        if (form1.date_from.value && !form1.date_to.value) {
            alert('请选择结束时间！');
            return false;
        }
        if (form1.date_from.value > form1.date_to.value) {

            alert('开始时间不能大于结束时间！');
            return false;
        }
        if (!form1.date_from.value && form1.date_to.value) {
            alert('请选择开始时间！');
            return false;
        }
        var count = form1.purchaseid.value;
        var count = Number(count);
        if (isNaN(count)) {

            alert('非法输入！');
            return false;
        }

    }

    function print(id, sid, pid) {

        if (sid != 10) {
            alert('该信息已处理！不能进行修改！');
            return false;
        }

        var url = "<?php echo url::base(TRUE)?>quality/editbadproducts?id=" + id + '&purchaseid=' + pid;
        //window.location.href=url;
        window.open(url);
        return false

    }


</script>
<script type="text/javascript">
    $(document).ready(function () {
        $('.table1 tbody tr:even').css("background-color", "#ffffff");

    })
</script>

